#!/bin/sh
# rm -f install-vuetorrent.sh && wget https://gitee.com/gemilk/image_repo/raw/master/nginx-vuetorrent/install-vuetorrent.sh && chmod +x install-vuetorrent.sh && ./install-vuetorrent.sh && rm -f install-vuetorrent.sh
CONFIG_SOURCE=$(docker inspect nginx | jq -r '.[].Mounts[] | select(.Destination == "/config") | .Source')


# 获取 PUID 和 PGID
PUID=$(docker inspect nginx | jq -r '.[].Config.Env[] | select(startswith("PUID=")) | split("=")[1]')
PGID=$(docker inspect nginx | jq -r '.[].Config.Env[] | select(startswith("PGID=")) | split("=")[1]')


if [ ! -d "$CONFIG_SOURCE" ]; then
    echo "Error: Directory $CONFIG_SOURCE does not exist."
    exit 1
fi

cd "$CONFIG_SOURCE"/www/
rm -rf vuetorrent*
wget https://github.com/VueTorrent/VueTorrent/releases/latest/download/vuetorrent.zip && unzip vuetorrent.zip

cd "$CONFIG_SOURCE"/nginx/site-confs/
rm -rf vuetorrent.conf
wget https://gitee.com/gemilk/image_repo/raw/master/nginx-vuetorrent/vuetorrent.conf && chown "$PUID":"$PGID" vuetorrent.conf

docker restart nginx